$(function(){	
showCondition(true,0,0,1,[]);
getDiffiGroupCharData();
//getDiffiGroupOverallData();
loadDiffiGroupTable();

});
/**
 * 获取全院理论疑难病组
 */
function getDiffiGroupOverallData(){
	var dateFrom=paramTabPage[tabId].dateFrom;
	var dateTo=paramTabPage[tabId].dateTo;
	$.post(contextPath+"/DifficultGroup/getOverallData.dhc",{"dateFrom":dateFrom,"dateTo":dateTo,"hospCode":paramTabPage[tabId].hospCode}).done(function(results){
	
	})
}
function getDiffiGroupCharData(){
	var dateFrom=paramTabPage[tabId].dateFrom;
	var dateTo=paramTabPage[tabId].dateTo;
	$.post(contextPath+"/DifficultGroup/getTotalCountDiffi.dhc",{"dateFrom":dateFrom,"dateTo":dateTo,"defalutType":"1","hospCode":paramTabPage[tabId].hospCode}).done(function(result){
		var data = result[0] ;
		//环形图
		var labelTop = {
			    normal : {
			        label : {
			            show : true,
			            position : 'center',
			            formatter : function (params){
			            	return params.series.data[1].value+"/"+params.series.data[0].value ;
			            },
			            textStyle: {
			                baseline : 'bottom',
			                color: '#000'
			            }
			        },
			        labelLine : {
			            show : false
			        }
			    }
			};
			var labelFromatter = {
			    normal : {
			        label : {
			            formatter : function (params){
			            	return (params.series.data[1].value/params.series.data[0].value*100).toFixed(2) + '%'
			            },
			            textStyle: {
			                baseline : 'top'
			            }
			        }
			    }
			}
			var labelBottom = {
			    normal : {
			        color: '#ccc',
			        label : {
			            show : true,
			            position : 'center'
			        },
			        labelLine : {
			            show : false
			        }
			    },
			    emphasis: {
			        color: 'rgba(0,0,0,0)'
			    }
			};
			var radius = [50, 70];
			var legend={bottom : 'bottom',itemGap: 60,data:['疑难病组全院占比(%)','疑难病组覆盖率(%)','疑难病组病例数占比(%)']};
			var series=[
					        {
					            type : 'pie',
					            center : ['15%', '40%'],
					            radius : radius,
					            avoidLabelOverlap:false,
					            label: {
					                normal: {
					                	show : true,
							            position : 'center',
							            formatter : formatNumKey(data.DIFFICOUNT,0)+"/"+formatNumKey(data.INCOUNT,0)+"\n"+formatNumKey(100*data.DIFFICOUNT/data.INCOUNT,2)+"%",
							            textStyle: {
							                baseline : 'bottom'
							            }
					                }
					            },
					            data : [
					                {name:'疑难病组全院占比(%)', value:data.DIFFICOUNT==null?0:data.DIFFICOUNT},
					                {name:'other', value:data.INCOUNT==null?0:data.INCOUNT-data.DIFFICOUNT}
					            ],
					            title:'dd'
					        },
					        {
					            type : 'pie',
					            center : ['45%', '40%'],
					            radius : radius,
					            avoidLabelOverlap:false,
					            label: {
					                normal: {
					                	show : true,
							            position : 'center',
							            formatter : formatNumKey(data.DIFFICOUNT,0)+"/"+formatNumKey(data.DIFFIAMOUNT,0)+"\n"+formatNumKey(100*data.DIFFICOUNT/data.DIFFIAMOUNT,2) +"%",
							            textStyle: {
							                baseline : 'bottom'
							            }
					                }
					            },
					            data : [
					                {name:'疑难病组覆盖率(%)', value:data.DIFFICOUNT==null?0:data.DIFFICOUNT},
					                {name:'other', value:data.DIFFIAMOUNT==null?0:data.DIFFIAMOUNT-data.DIFFICOUNT}
					            ],
					            title:'dd'
					        },
					        {
					            type : 'pie',
					            center : ['75%', '40%'],
					            radius : radius,
					            avoidLabelOverlap:false,
					            label: {
					                normal: {
					                	show : true,
							            position : 'center',
							            formatter : formatNumKey(data.DIFFICNT,0)+"/"+formatNumKey(data.INCNT,0)+"\n"+formatNumKey(100*data.DIFFICNT/data.INCNT,2)+"%",
							            textStyle: {
							                baseline : 'bottom'
							            }
					                }
					            },
					            data : [
					                {name:'疑难病组病例数占比(%)', value: data.DIFFICNT==null?0:data.DIFFICNT},
					                {name:'other', value: data.INCNT==null?0:data.INCNT-data.DIFFICNT}
					                
					            ],
					            title:'ddd'
					        }
					    ];
		doughnutChart($('#'+tabId+' #diffiGroupChar'),legend,series);
		
	})
}
/**
 * 格式化数字
 * @param {} num
 * @param {} decimal
 * @return {}
 */
function formatNumKey(num,decimal) {
	if(!num || isNaN(num)) {
		if(isNaN(decimal)) {
			return decimal ;
		} else {
			return formatNumber("0",decimal) ;
		}
	} 
	return formatNumber(num,decimal)
}

/**
 * 加载疑难病组首页列表
 * @returns
 */
function loadDiffiGroupTable(){
	var quotaCodes = ['InCaseCnt','CMI','TotalWeight','AvgDays','TimeEff','AvgFee','FeeEff','AvgDrugFee','AvgMateFee','AvgDrugMateFee','RiskLevel','DeadCaseCnt','DeadRatio'] ;
	var quotaCode = quotaCodes.join(",") ;
	var param = drgUI.setAjaxData(tabId);
	param.quotaCode = quotaCode;
	param.monitorType="drgs";
	param.isDifDisGroup = "1";
	$.post(contextPath+'/DrgsIndexCal/indexCal.dhc',param).done(function(result){
		var data = result.data;
	  	var columns=[
		{"className":"details-control",
		"data":null,
		"width" : '30px',
		"defualtContent":''},
		{"data":"DRG",
			 "createdCell":function(nTd,sData,oData,iRow,iCol){
				$(nTd).attr('limit', 24);
				  $(nTd).limit();
			 },
			 "render":function(obj,type,full){
				 return full.ccode+'-'+full.ddesc;
			 }
		},
		{"data":"InCaseCnt",
			"render":function(obj,type,full){
				return "<a href=\"javascript:loadCaseDtl('入组病例数','"+full.ccode+"','drgs','InCaseCnt')\" >"+full.InCaseCnt+"</a>";
			}},
		{"data":"CMI"},
		{"data":"TotalWeight"},
		{"data":"AvgDays"},
		{"data":"TimeEff"},
		{"data":"AvgFee"},
		{"data":"FeeEff"},
		{"data":"AvgDrugFee"},
		{"data":"AvgMateFee"},
		{"data":"AvgDrugMateFee"},
		{"data":"DRG_DEAD_LEVEL",
			render:function(obj,type,full){
				var deadLevel = "";
				if(full.RiskLevel == 0){
					deadLevel = "零风险";
				}else if(full.RiskLevel == 1){
					deadLevel = "低风险";
				}else if(full.RiskLevel == 2){
					deadLevel = "中低风险";
				}else if(full.RiskLevel == 3){
					deadLevel = "中高风险";
				}else if(full.RiskLevel == 4){
					deadLevel = "高风险";
				}else{
					deadLevel = "";
				}
				return deadLevel;
			}},
		{"data":"DeadCaseCnt",
				"render":function(obj,type,full){
					var deadCaseCntValue=full.DeadCaseCnt;
					if(deadCaseCntValue>0){
						return "<a href=\"javascript:loadCaseDtl('死亡病例数','"+full.ccode+"','drgs','DeadCaseCnt')\" >"+full.DeadCaseCnt+"</a>";
					}else{
						return deadCaseCntValue;
					}
					
				}},
		{"data":"DeadRatio"}
		];
		var paramTableDatas={order:[[1,"asc"]],"columnDefs":[{"orderable":false,"targets":[0]}]};
			var oaTable=$("#"+tabId+" #diffiGroupTable").dataTableBasic(columns,data,paramTableDatas);
			$("#"+tabId+" #diffiGroupTable").find("tbody").off("click", "td.details-control");
			$("#"+tabId+" #diffiGroupTable").find("tbody").on('click', 'td.details-control', function (){
				var nTr = $(this).closest('tr');
				var row = oaTable.row( nTr );
		        var aData = row.data();
		        if (row.child.isShown()) {//判断是否已打开
					row.child.hide();
					nTr.removeClass("shown");
				} else {
					nTr.addClass("shown");
					//获取要查询的关联指标的指标代码
					fnFormatDetails(row,aData.ccode);
				}
		    
			});
	});
}
function fnFormatDetails(row,drgCode){
	var quotaCodes = ['InCaseCnt','TotalWeight','AvgDays','TimeEff','AvgFee','FeeEff','AvgDrugFee','AvgMateFee','AvgDrugMateFee','DeadCaseCnt','DeadRatio'] ;
	var quotaCode = quotaCodes.join(",") ;
	var param = drgUI.setAjaxData(tabId);
	param.quotaCode = quotaCode;
	param.monitorType="dep";
	param.pardrgCode = drgCode;
	param.isDifDisGroup = "1";
	$.ajax({
	url:contextPath+"/DrgsIndexCal/indexCal.dhc",
	data:param,
	type:"post",
	async:false,
	success:function(result){
		if(result!="" && result.data!=""){
			var data = result.data.sort(function(a,b){
				return b.InCaseCnt-a.InCaseCnt;
			})
		row.child("正在加载...").show();
				try{
					var str = '';
					str+=' <table width="100%"  >  ';
					str+=' 	<thead>  ';
					str+=' 		<tr>  ';
					str+=' 			<td>科室</td>  ';
					str+=' 			<td>入组病例数</td>  ';
					str+=' 			<td>总权重</td>  ';
					str+=' 			<td>平均住院日</td>  ';
					str+=' 			<td>时间消耗指数</td>  ';
					str+=' 			<td>次均费用</td>  ';
					str+=' 			<td>费用消耗指数</td>  ';
					str+=' 			<td>次均药品费用</td>  ';
					str+=' 			<td>次均耗材费用</td>  ';
					str+=' 			<td>次均药品耗材费用</td>  ';
					str+=' 			<td>死亡病例数</td>  ';
					str+=' 			<td>死亡率(%)</td>  ';
					str+=' 		</tr>  ';
					str+=' 	</thead>  ';
					str+=' 	<tbody>  ';
					for(var i=0;i<data.length;i++){
						str += "	<tr>";
						str+='<td>'+data[i].ddesc+'</td>';
						if(data[i].InCaseCnt>0){
							str+='<td><a href="javascript:loadCaseDtl(\'入组病例数\',\''+data[i].ccode+'\',\'dep\',\'InCaseCnt\',\''+drgCode+'\')" >'+data[i].InCaseCnt+'</a></td>';
						}else{
							str+='<td>'+data[i].InCaseCnt+'</td>';
						}
						str+='<td>'+data[i].TotalWeight+'</td>';
						str+='<td>'+data[i].AvgDays+'</td>';
						str+='<td>'+data[i].TimeEff+'</td>';
						str+='<td>'+data[i].AvgFee+'</td>';
						str+='<td>'+data[i].FeeEff+'</td>';
						str+='<td>'+data[i].AvgDrugFee+'</td>';
						str+='<td>'+data[i].AvgMateFee+'</td>';
						str+='<td>'+data[i].AvgDrugMateFee+'</td>';
						if(data[i].DeadCaseCnt>0){							
							str+='<td><a href="javascript:loadCaseDtl(\'死亡病例数\',\''+data[i].ccode+'\',\'dep\',\'DeadCaseCnt\',\''+drgCode+'\')" >'+data[i].DeadCaseCnt+'</a></td>';
						}else{
							str+='<td>'+data[i].DeadCaseCnt+'</td>';
						}
						
						
						str+='<td>'+data[i].DeadRatio+'</td>';
					}
					str+=' 	</tbody>  ';
					str+=' </table>  ';
					row.child(str).show();
				}catch(e){
					row.child("出错了...").show();
				}
		}
				
		}
})
}






function loadCaseDtl(title,ccode,monitorType,quotaCode,drgCode){
	var param = drgUI.setAjaxData(tabId);
	param.caseLinkCode=quotaCode;
	if(monitorType == "depGroup"){
		param.depGroupCode=ccode;
	}else if(monitorType == "dep"){
		param.depCode=ccode;
		param.drgCode=drgCode;
	}else if(monitorType == "ward"){
		param.wardCode=ccode;
	}else if(monitorType == "clinic"){
		param.groupName=ccode;
	}else if(monitorType == "protomedicus"){
		param.protomedicus=ccode;
	}else if(monitorType == "physician"){
		param.physician=ccode;
	}else if(monitorType == "resident"){
		param.resident=ccode;
	}else if(monitorType == "mdc"){
		param.mdcCode=ccode;
	}else if(monitorType == "adrg"){
		param.adrgCode=ccode;
	}else if(monitorType == "drgs"){
		param.drgCode=ccode;
	}
	openTab('/pages/drgscommon/case.jsp', title+"|"+"病例明细", "caseDtl"+monitorType+ccode+quotaCode, "caseDtl"+monitorType+ccode+quotaCode, param);
}

/**
 * 弹出疑难病组维护页面
 * @returns
 */
function diffiGroupMaintain(){
		 $.post( contextPath + '/pages/common/top-dialog.jsp').done(function(data){
				var dialog  = $(data);
				dialog.find(".modal-dialog").attr("id","diffiGroupMaintain_dialog_id");
				dialog.find(".modal-title").html("疑难病组维护");
				dialog.modal({
					keyboard: false
				}).on({'hidden.bs.modal' : function(){
						$(this).remove();
						searchByCondition();
					   },'shown.bs.modal' : function(){
						    var str="";
						    str+="";
						    str+=" <div class='row rowhcq'> ";
						    str+=" <div class='col-xs-12'> ";
						    str+="  <div class='boxcq clearfix'> ";
						    str+="     <div class='ti'><i class='fa fa-file-text-o'></i>疑难病组维护</div> ";
						    str+="      <ul class='nav nav-tabs boxnavcq' role='tablist'></ul> ";
						    str+="       <div class='clearfix'></div> "; 
						    str+="      <div class='col-xs-12' style = 'margin: 10px 0px;'> ";
						    str+="      	<div class='col-xs-6'> ";
						    str+="      		<div>    ";
						    str+="  			<div class='col-xs-5'> <label class='pull-right' style = 'height:30px;line-height:30px;'>筛选时间范围</label> </div>  ";
						    str+=" 	            <div class='col-xs-3'> <select id = 'diffiGroupSelect' class='multiselect ' multiple='multiple'> </select> </div>    ";
						    str+="             	<div class='col-xs-4'> <button class='form-control pull-right btn btn-success' onclick = 'setDiffiGroup()'> 确定</button> </div>  ";
						    str+=" 	      </div>      ";
						    str+="     <div class='clearfix'> </div>   ";
						    str+="      		<div>   ";
						    str+="         			<div class='col-xs-5'> <label class='pull-right' style = 'height:30px;line-height:30px;'>入组病例数占比排名前</label> </div>   ";
						    str+="              	<div class='col-xs-3'> <div class='input-group'>  <input class='form-control sliderValue' type='text' value = '80'/> <div class= 'input-group-addon'>%</div> </div> </div>  ";
						    str+="               	<div class='col-xs-4'> <input class='filterSlider' type='text'/> </div>  ";
						    str+="       		</div>  ";
						    str+="         		<div class='clearfix'></div>   ";
						    str+="          		<div>    ";
						    str+="           			<div class='col-xs-5'> <label class='pull-right' style = 'height:30px;line-height:30px;'>各MDC内病组权重占比排名前</label> </div>   ";
						    str+="   	            	<div class='col-xs-3'> <div class='input-group'> <input class='form-control sliderValue' type='text' value = '80'/> <div class='input-group-addon' >%</div>  </div> </div>  ";
						    str+="   	            	<div class='col-xs-4'> <input class='filterSlider' type='text'/> </div>   ";
						    str+="          		</div>  ";
						    str+="          	</div>  ";
						    str+="       	<div class='col-xs-6'>   ";
						    str+="         		<div class='zhujie' style = 'padding:5px;line-height:30px; border-radius: 10px;box-shadow: 0 15px 80px rgba(0, 0, 0, .2);'>   ";
						    str+="        			1、将各DRG病组的入组病例数由高到低排名，取占总病组数排名前<span id = 'groupCntPer'>80</span>%病组；<br/>   ";
						    str+=" 					2、将各MDC内的DRG病组按照权重排名，取占总病组数排名前<span id = 'mdcWeightPer'>80</span>%病组；<br/>     ";
						    str+=" 					3、同时满足两个个条件病组为疑难病组。     ";
						    str+="   		</div>    ";
						    str+="  	</div>       ";
						    str+="   </div>          ";
						    str+="   <div class='col-xs-12'> <div id='diffiGroupMdcDiv'></div> </div>     ";
						    str+="   </div>     ";
						    str+="   </div>     ";
						    str+="   </div>     ";
						    
							dialog.find(".modal-dialog").width(1200);
							dialog.find(".modal-body").empty();
							dialog.find(".modal-body").append(str);
							
							var perConfig = [];
							var yearConfig = [];
							var years = [];
							//筛选时间范围方法
							$.ajax({
								url : contextPath + "/DifficultGroup/getKeyFilterInit.dhc",
								type : "post",
								dataType : "json",
								async : false,
								data : {"hospCode":paramTabPage[tabId].hospCode},
								success : function(result) {
									if(result.success && result.data){
										years = result.data.years;
										var cfg = "" ;
										if(result.data.cfg) {
											var cfg = result.data.cfg;
											yearConfig=cfg.split("θ")[0]!=undefined? cfg.split("θ")[0].split(","):'';
											perConfig= cfg.split("θ")[1]!=undefined? cfg.split("θ")[1].split(","):'';
										}
										var optStr = "";
										if(years.length>0){
											for(var i = 0;i<years.length;i++){
												optStr = optStr + "<option value="+years[i]+">"+years[i]+"</option>";
											}
											dialog.find("#diffiGroupSelect").append(optStr);
										}else{
											dialog.find(".multiselect").multiselect('select', 0);
										}
										
										//多选下拉框初始化
										if(yearConfig.length==0&&years.length>0){
											dialog.find(".multiselect").multiselect('select', years[years.length-1]);//截取最后一个
										}else if(yearConfig.length>0){
											dialog.find(".multiselect").multiselect('select', yearConfig);
										}
										if(perConfig.length==0){
											//调整滑块
											dialog.find(".filterSlider").slider({//把滑块的最小值调整到0
												min: 0, max: 100, range: false, value: 80,
											    reversed : false
											});
										}else{
											//调整滑块
											dialog.find(".filterSlider:eq(0)").slider({//把滑块的最小值调整到0
												min: 0, max: 100, range: false, value: perConfig[0],
											    reversed : false
											});
											dialog.find(".sliderValue:eq(0)").val(perConfig[0]);
											dialog.find("#groupCntPer").html(perConfig[0]);
											
											//调整滑块
											dialog.find(".filterSlider:eq(1)").slider({//把滑块的最小值调整到0
												min: 0, max: 100, range: false, value: perConfig[1],
											    reversed : false
											});
											dialog.find(".sliderValue:eq(1)").val(perConfig[1]);
											dialog.find("#mdcWeightPer").html(perConfig[1]);
										}
									}
								}
							});
							dialog.find(".filterSlider:eq(0)").on("slide", function(slideEvt) {
								var groupCntPerValue=slideEvt.value;
								$(this).parent().parent().find("input:eq(0)").val(slideEvt.value);
								dialog.find("#groupCntPer").html(groupCntPerValue);
							});
							dialog.find(".filterSlider:eq(1)").on("slide", function(slideEvt) {
								var weightPerValue=slideEvt.value;
								$(this).parent().parent().find("input:eq(0)").val(weightPerValue);
								dialog.find("#mdcWeightPer").html(weightPerValue);
							});
							//input 框值改变事件
							dialog.find(".sliderValue:eq(0)").blur(function(e){  
								var perValue=$(this).val();
								if(!/^([1-9]\d?|100)$/.test(perValue))
								{
									drgUI.warning('请输入0-100之间的整数');
									$(this).val(80);
									dialog.find(".filterSlider:eq(0)").slider("setValue",80);
									dialog.find("#groupCntPer").html(80);
									return;
								}
								dialog.find(".filterSlider:eq(0)").slider("setValue",perValue);
								dialog.find("#groupCntPer").html(perValue);
							});
							dialog.find(".sliderValue:eq(1)").blur(function(e){  
								var perValue=$(this).val();
								if(!/^([1-9]\d?|100)$/.test(perValue))
								{
									drgUI.warning('请输入0-100之间的整数');
									$(this).val(80);
									dialog.find(".filterSlider:eq(1)").slider("setValue",80);
									dialog.find("#weightPer").html(80);
									return;
								}
								dialog.find(".filterSlider:eq(1)").slider("setValue",perValue);
								dialog.find("#mdcWeightPer").html(perValue);
							});
							dialog.find(".tooltip-arrow").css("display","none");
							dialog.find(".tooltip-inner").css("display","none");
							dialog.find(".slider").width(160);
							dialog.find("#diffiGroupSelect").next(".btn-group").width(100);
							dialog.find("#diffiGroupSelect").next(".btn-group").find("button").width(100);
							dialog.find(".sliderValue").width(66);
							
							showDiffiGroupMdcLevel();
							dialog.find(".modal-footer").css("display","none");
			              }
			      });

			});
	
}

/**
 * 加载疑难病组列表
 * @returns
 */
function showDiffiGroupMdcLevel(){
		var newDialog=$("#diffiGroupMaintain_dialog_id");
		var selected = [];
		newDialog.find(".multiselect option:selected").each(function () {
			selected.push($(this).val());
		});
		if(selected.length==0){
			return;
		}
		newDialog.find('#diffiGroupMdcDiv').html('<table id="diffiGroupMdcTable" class="table"></table>');
		$.post(contextPath+"/DifficultGroup/getDiffiGroupMdc.dhc",{"yearCode":selected,"hospCode":paramTabPage[tabId].hospCode}).done(function(data){
			var columns=[
		                  	{"data": null,"sClass": "details-control"},
		                  	{"data": "MDC_CODE","title":'MDC',
		                  		"render": function(obj, type, full) {
		                  			return  full["MDC_CODE"]+"-"+full["MDC_DESC"];
			                      }
	                  		},
		                  	{"data": "DRG_COUNT","title":'疑难病组数' },
		                  	{"data": "IN_CNT","title":'病例数',
	                  			"render": function(obj, type, full) {
	                  				if(full["IN_CNT"]!=null) {
	                  					return full["IN_CNT"] ;
	                  				} else {
	                  					return "-" ;
	              					}
			                      }
	              			},
		                  	{"data": "ALL_WEIGHT","title":'总权重',
	              				"render": function(obj, type, full) {
	                  				if(full["ALL_WEIGHT"]!=null){
	                  					return full["ALL_WEIGHT"] ; 
	                  				} else {
	                  					return "-";
	              					}
			                      }
		                  	},
		                  	{"data": "CMI","title":'CMI',
		                  		"render": function(obj, type, full) {
	                  				if(full["CMI"]!=null){
	                  					return full["CMI"] ;
	                  				} else {
	                  					return "-";
	              					}
			                      }
	                  		}
		                 ];
			var paramsDataTables={lengthChange:false,ordering:false,stateSave:true,info:false,tableTitle:'重点病组MDC',columnDefs:[{"orderable": false,"targets": [ 0 ] }]};
			paramsDataTables.buttons=[{"text": '增加病组',"action": function ( e, dt, node, config) {showAddDiffiGroup();}},{"text": '疑难病组明细',"action": function ( e, dt, node, config) {showDiffiGroupDrgDlg();}}];
			var obTable=newDialog.find("#diffiGroupMdcTable").dataTableBasic(columns,data,paramsDataTables);
				function format ( d ) {
				    // `d` is the original data object for the row
				    return '<div class="col-xs-12" style="background:#eee;">'
						    +'	<div class="row">'
					        +'		<div class="col-xs-12" id= "'+d+'"></div>'
					        +'   </div>'
					        +'</div>';
				}
				newDialog.find('#diffiGroupMdcTable tbody').on('click', 'td.details-control', function () {
					var nTr = $(this).closest('tr');
					var row = obTable.row( nTr );
			        var aData = row.data();
			        if (row.child.isShown()) //判断是否已打开
					{
						row.child.hide();
						nTr.removeClass("shown");
					} else {
						nTr.addClass("shown");
			        	var mdcCode = aData.MDC_CODE ;
			        	row.child(format(mdcCode)).show();
			            diffiGroupInMdc(mdcCode);
			        }
			    } );
		});
	
}
/**
 * 
 * MDC展开
 */
function diffiGroupInMdc(mdcCode){
		var newDialog=$("#diffiGroupMaintain_dialog_id");
	    var tid='id'+new Date().getTime();
	    var mdcTableData = getDiffiGroupDataDrg(mdcCode);
	    newDialog.find('#'+mdcCode).html('<table id="'+tid+'" class="table"></table>');
		var columns=[
	               	{"data": "DRGINFO","title":'DRG代码及描述',
	              		"render": function(obj, type, full) {
	          				if(full["DRG_CODE"]!=null)
	      					{
	          					return full["DRG_CODE"]+"-"+full["DRG_DESC"];
	      					}
	          				else
	      					{
	          					return "("+full["DRG_DESC"]+")";
	      					}
	                      }
	          		},
	              	{"data": "CASECNT","title":'病例数',
	          			"render": function(obj, type, full) {
	          				if(full["IN_CNT"]!=null)
	      					{
	          					return full["IN_CNT"];
	      					}
	          				else
	      					{
	          					return "-";
	      					}
	                      }
	          		},
	              	{"data": "ALL_WEIGHT","title":'总权重',
	          			"render": function(obj, type, full) {
	          				if(full["ALL_WEIGHT"]!=null)
	      					{
	          					return full["ALL_WEIGHT"];
	      					}
	          				else
	      					{
	          					return "-";
	      					}
	                      }
	          		},
	              	{"data": "WEIGHT","title":'权重',
	          			"render": function(obj, type, full) {
	          				if(full["DRG_WEIGHT"]!=null)
	      					{
	          					return full["DRG_WEIGHT"];
	      					}
	          				else
	      					{
	          					return "-";
	      					}
	                      }
	          		},
	              	{"data": "operation","title":'操作',
	              		"render": function(obj, type, full) {
	              			return "<a href = \"javascript:delDiffiGroup('"+full.DRG_CODE+"','mdclevel')\">删除</a>";
		            	   }
	          		}
	             ];
		var paramsDataTables={tableTitle:mdcCode+'-重点病组',lengthChange:false,ordering:false,stateSave:true,info:false,columnDefs:[{"orderable": false,"targets": [ 0 ] }]};
		newDialog.find("#"+tid).dataTableBasic(columns,mdcTableData,paramsDataTables);
	}
//查询MDC展开DRG数据
function getDiffiGroupDataDrg(mdcCode){
		var newDialog=$("#diffiGroupMaintain_dialog_id");
		var selected = [];
		newDialog.find(".multiselect option:selected").each(function () {
			selected.push($(this).val());
		});
		var aData = [];
		$.ajax({
			url : contextPath + "/DifficultGroup/getDiffiGroupDrg.dhc",
			type : "post",
			dataType : "json",
			data : {
				"yearCode":selected,
				"mdcCode":mdcCode,
				"hospCode":paramTabPage[tabId].hospCode
			},
			async : false,
			success : function(data) {
				aData = data;
			}
		});
		return aData;
}
function delDiffiGroup(drgCode,level){	
		drgUI.confirm({
			content : '确认删除吗?',
			callSure : function() {
				$.post(contextPath +"/DifficultGroup/delDiffiGroup.dhc",{'drgCode':drgCode,"hospCode":paramTabPage[tabId].hospCode},function(result){
					
					if(level=="mdclevel")
					{
						showDiffiGroupMdcLevel();//重新加载MDC层级疑难病组的详情
					}
					else
					{
						showDiffiGroupMdcLevel();//重新加载MDC层级疑难病组的详情
						diffiGroupDrgDataTable();//重新加载DRG层级疑难病组的详情
					}
					//清除全部缓存
					$.post(contextPath+"/ClearCache/clearCache.dhc",function(data){});
				});
			}
		});
}

/**
 * 增加病组弹出页面
 * @returns
 */
function showAddDiffiGroup(){
		 $.post(contextPath + '/pages/common/top-dialog.jsp').done(function(data){
				var dialogadd  = $(data);
				dialogadd.find(".modal-dialog").attr("id","diffiGroupFilter_dialog_add");
				dialogadd.find(".modal-title").html("添加病组");
				dialogadd.modal({
					keyboard: false
				}).on({
					'hidden.bs.modal' : function(){
						$(this).remove();
					},
					'shown.bs.modal' : function(){
						dialogadd.find("#echartcq4").html("<table id = 'addDiffiGroupTable' width = '100%' style='white-space:nowrap'><thead><tr><th>MDC代码</th><th>MDC描述</th><th>DRG代码</th><th>DRG描述</th><th>病例数</th><th>病例数排名</th><th>权重</th><th>总权重</th><th>总权重排名</th><th width = '10%'>操作</th></tr></thead><tbody></tbody></table>");
						addDiffiGroupTable();
					}
				});
		 });
	}
/**
 * 展示其它非疑难病组列表
 * @returns
 */
function addDiffiGroupTable(){
		var newDialog=$("#diffiGroupFilter_dialog_add");
		var addDiffiGroupTableData = getExtraDiffiGroup();
		var columns=[	
	                 {"data": "MDCCODE"},
	                 {"data": "MDCDESC",
	             	  "render": function(obj, type, full) {
	             		  if(full["MDCDESC"]==null) {
	             			  return full["MDCCODE"] ;
	         			  } else {
	         				  return "-";
	     				  }
	             	  }
	                 },
	               	{"data": "DRGCODE" },
	               	{"data": "DRGDESC",
	           			"render": function(obj, type, full) {
		              				if(full["DRGDESC"]!=null) {
		              					return full["DRGDESC"] ;
		              				} else {
		              					return "-";
		          					}
		                      }
	       			},
	               	{"data": "CASECNT",
	       				"render": function(obj, type, full) {
	           					if(full["CASECNT"]!=null){
	           						return full["CASECNT"] ;
	           					} else {
	               					return "-";
	           					}
		                      }
	   				},
	               	{"data": "CASECNTRANGE",
	   					"render": function(obj, type, full) {
	       						if(full["CASECNTRANGE"]!=null){
	       							return full["CASECNTRANGE"] ;
	       						} else {
	               					return "-";
	           					}
		                      }
						},
	               	{"data": "WEIGHT",
							"render": function(obj, type, full) {
		  							if(full["WEIGHT"]!=null) {
		  								return full["WEIGHT"] ;
		  							} else {
		              					return "-";
		          					}
		                      }
						},
	               	{"data": "TOTALWEIGHT",
							"render": function(obj, type, full) {
									if(full["TOTALWEIGHT"]!=null){
										return full["TOTALWEIGHT"] ;
		  							} else {
		              					return "-";
		          					}
		                      }
							},
	               	{"data": "TOTALWEIGHTRANGE",
								"render": function(obj, type, full) {
									if(full["TOTALWEIGHTRANGE"]!=null){
										return full["TOTALWEIGHTRANGE"] ;
	   							} else {
	               					return "-";
	           					}
		                      }
	           		},
	               	{"data": "operation",
	               		"render": function(obj, type, full) {
	               			return "<a href = \"javascript:addDiffiGroup('"+full["DRGCODE"]+"')\">添加</a>";
		                      }
	           		}
	              ];
		var paramsDataTables={lengthChange:false,info:false,scrollX:true,scrollY:'300px',columnDefs:[{"orderable": false,"targets": [ 9 ] },{ "visible": false, "targets": [1]}]};
		newDialog.find("#echartcq4 #addDiffiGroupTable").dataTableBasic(columns,addDiffiGroupTableData,paramsDataTables);
	}
/**
 * 获取其它非疑难病组列表
 * @returns
 */
function getExtraDiffiGroup(){	
		var depCode = paramTabPage[tabId].depCode ;
		var newDialog=$("#diffiGroupMaintain_dialog_id");
		var selected = [];
		newDialog.find(".multiselect option:selected").each(function () {
			selected.push($(this).val());
		});
		var aData = [];
		$.ajax({
			url : contextPath + "/DifficultGroup/getExtraDiffiGroup.dhc",
			type : "post",
			dataType : "json",
			data : {
				"yearCode":selected,
				"hospCode":paramTabPage[tabId].hospCode
			},
			async : false,
			success : function(result) {
				aData = result.data;
			}
		});
		return aData;
}
//添加疑难病组
function addDiffiGroup(drgCode){	
		var depCode = paramTabPage[tabId].depCode ;
		$.post(contextPath + '/DifficultGroup/addDiffiGroup.dhc',{"drgCode":drgCode,"hospCode":paramTabPage[tabId].hospCode}).done(function(data){
			//清除全部缓存
			$.post(contextPath+"/ClearCache/clearCache.dhc",function(data){});
			//刷新当前表格和mdc表格
			showDiffiGroupMdcLevel();
			addDiffiGroupTable();
			drgUI.success('添加病组成功');
		});
	
}
//疑难病组明细
function showDiffiGroupDrgDlg(){
		 $.post(contextPath + '/pages/common/top-dialog.jsp').done(function(data){
				var dialog  = $(data);
				dialog.find(".modal-title").html("疑难病组明细");
				dialog.find(".modal-dialog").attr("id","diffiGroupMaintain_dialog_det");
				dialog.modal({
					keyboard: false
				}).on({
					'hidden.bs.modal' : function(){
						$(this).remove();
					},
					'shown.bs.modal' : function(){
						dialog.find("#echartcq4").html("<table id = 'diffiGroupDetailTable' width = '100%' ><thead><tr><th>MDC代码</th><th>MDC描述</th><th>DRG代码</th><th>DRG描述</th><th>病例数</th><th>病例数排名</th><th>权重</th><th>总权重</th><th>总权重排名</th><th width = '10%'>操作</th></tr></thead><tbody></tbody></table>");
						diffiGroupDrgDataTable()
					}
				});
		 });
}
function diffiGroupDrgDataTable(){
		var newDialog=$("#diffiGroupMaintain_dialog_det");
		var diffiGroupDetailTableData = getDiffiGroupDataDrg();
		var columns=[
	                 {"data": "MDC_CODE" },
	                 {"data": "MDCDESC",
	             	  "render": function(obj, type, full) {
	             		  if(full["MDC_DESC"]!=null) {
	             			  return full["MDC_DESC"] ;
	             		  } else {
	         				  return "-";
	     				  }
	             	  }
	                 },
	               	{"data": "DRG_CODE" },
	               	{"data": "DRGDESC",
	           			"render": function(obj, type, full) {
	           				if(full["DRG_DESC"]!=null) {
	           					return full["DRG_DESC"] ;
	           				}
	           				else {
	           					return "-";
	       					} 
		                     }
	       			},
	               	{"data": "CASECNT",
	       				"render": function(obj, type, full) {
	       					if(full["IN_CNT"]!=null) {
	       						return full["IN_CNT"];
	       					} else   {
	           					return "-";
	       					}
		                      }
	   				},
	               	{"data": "CASECNTRANGE",
	   					"render": function(obj, type, full) {
	   						if(full["INCNT_DESC"]!=null){
	   							return full["INCNT_DESC"] ;
	   						} else {
	           					return "-";
	       					} 
		                      }
						},
	               	{"data": "WEIGHT",
							"render": function(obj, type, full) {
								if(full["DRG_WEIGHT"]!=null) {
									return full["DRG_WEIGHT"] ;
								} else {
	           					return "-";
	       					}
		                      }
						},
	               	{"data": "TOTALWEIGHT",
							"render": function(obj, type, full) {
								if(full["ALL_WEIGHT"]!=null) {
									return full["ALL_WEIGHT"] ;
								} else {
	           					return "-";
	       					}
		                      }
							},
	               	{"data": "TOTALWEIGHTRANGE",
							"render": function(obj, type, full) {
								if(full["WEIGHT_DESC"]!=null) {
									return full["WEIGHT_DESC"] ;
								} else {
									return "-";
								}
	                     }
	           		},
	               	{"data": "operation",
	               		"render": function(obj, type, full) {
	               			return "<a href = \"javascript:delDiffiGroup('"+full.DRG_CODE+"','drglevel')\">删除</a>";//将full[0]改为full[2]   重点病组明细删除
		                      }
	           		}
	              ];
		var paramsDataTables={lengthChange:false,searching:false,stateSave:true,info:false,tableTitle:'',columnDefs:[{"orderable": false,"targets": [ 9 ] },{ "visible": false, "targets": [1]}]};
		newDialog.find("#echartcq4 #diffiGroupDetailTable").dataTableBasic(columns,diffiGroupDetailTableData,paramsDataTables);
	
}

/**
 * 保存筛选条件，并获取疑难病组
 * @returns
 */
function setDiffiGroup(){
		var depCode = paramTabPage[tabId].depCode ;
		var newDialog=$("#diffiGroupMaintain_dialog_id");
		var caseRatio = newDialog.find(".filterSlider:eq(0)").val();//入组病例数占比
		var mdcWeightRatio = newDialog.find(".filterSlider:eq(1)").val();//mdc权重占比
		var selected = [];
		newDialog.find(".multiselect option:selected").each(function () {
			selected.push($(this).val());
		});
		if(selected.length==0){
			drgUI.warning('年份不能为空');
			return ;
		}
		drgUI.confirm({
			content : '确认后原有的疑难病组将被清除?',
			callSure : function() {
				$.post(contextPath + '/DifficultGroup/setDiffiGroup.dhc',{
						"yearCode":selected,
						"caseCntPer":caseRatio,
						"mdcWeightPer":mdcWeightRatio,
						"hospCode":paramTabPage[tabId].hospCode
					}
				).done(function(data){
					//显示遮罩层
					drgUI.success('本次确认'+data.data+'个疑难病组');
					//清除全部缓存
					$.post(contextPath+"/ClearCache/clearCache.dhc",function(data){})
					//重新加载新的疑难病组数据
					showDiffiGroupMdcLevel();
				});
			}
		});
}